(deftemplate testira
	(slot id)
	(slot prasanje)
    (slot odgovor)
    (slot odgovor_da)
    (slot odgovor_ne)	
)


(deftemplate test
  (slot action)
  (slot next)
  (slot tst) 
)

(defrule init
	(not(testira (id test0)))
	=>
	(load-facts "test.txt")
	(assert(tekoven_test test0))
)

(defrule prasanje
	?fact1 <- (tekoven_test ?br_test)
	(testira(id ?br_test) (prasanje ?br_prasanje))
	(not(odgovor ?))
	=>
	(printout t ?br_prasanje " Da / Ne ")
	(assert (odgovor (read)))
)

(defrule proveri_prasanje
	?fact1 <- (odgovor ~da&~ne)
	=>
	(retract ?fact1)
)

(defrule da
	?fact1 <- (odgovor da)
	?fact2 <- (tekoven_test ?br_test)
	(testira(id ?br_test)(odgovor_da ?tocno))
	=>
	(retract ?fact1 ?fact2)
	(assert(tekoven_test ?tocno))
)

(defrule ne
	?fact1 <- (odgovor ne)
	?fact2 <- (tekoven_test ?br_test)
	(testira(id ?br_test)(odgovor_ne ?ne_tocno))
	=>
	(retract ?fact1 ?fact2)
	(assert(tekoven_test ?ne_tocno))
)


(defrule print
 	 ?fact1 <- (tekoven_test ?br_test)
 	 (test
 	 (action ?action) (next ?next)(tst ?br_test))
 	 =>
 	 (printout t "Spored vasite baranja go imate sledniov odgovor: " crlf)
 	 (printout t "next: " ?next crlf)
 	 (printout t "action: " ?action crlf)

 	 (assert(print done))
 	 (retract ?fact1)
)


(defrule pak
	?fact1 <- (print done)
	=>
	(printout t "Sakate li da se obidete povtorno ?" crlf)
	(assert(sakas_pak(read)))
	(assert(vneseno))
	(retract ?fact1)
)

(defrule povtorno_proveri
	?fact1 <- (vneseno)
	?fact2 <- (sakas_pak ~da&~ne)
	=>
	(assert(print done))
	(retract ?fact1 ?fact2)
)

(defrule povtorno_da
	?fact1 <- (vneseno)
	?fact2 <- (sakas_pak da)
	=>
	(assert(tekoven_test test0))
	(retract ?fact1 ?fact2)
)

(defrule povtorno_ne
	?fact1 <- (vneseno)
	?fact2 <- (sakas_pak ne)
	=>
	(printout t "Cao!!!" crlf)
	(retract ?fact1 ?fact2)
)

